package com.cbry.easyddl.enums;


/**
 * @Classname MySqlTypeEnum
 * @Description
 * @Date 2024/4/27 15:29
 * @Created by liaoxg
 */
public enum MySqlTypeEnum {

    // 基础类型
    BASE_BYTE_ARRAY("byte[]", "tinyint", "(4)",  "byte"),
    BASE_BYTE("byte", "blob", "",  "byte[]"),

    BASE_INT("int", "int", "(11)",  "int"),
    BASE_SHORT("short", "smallint", "(6)",  "short"),
    BASE_LONG("long", "bigint", "(20)",  "long"),
    BASE_FLOAT("float", "float", "",  "float"),
    BASE_DOUBLE("double", "double", "",  "double"),
    BASE_BOOLEAN("boolean", "tinyint", "(4)",  "boolean"),
    BASE_CHAR("char", "char", "(1)",  "char"),

    // 封装类型
    BYTE("java.lang.Byte" , "tinyint" , "(4)","Byte"),
    INTEGER("java.lang.Integer", "int", "(11)",  "Integer"),
    SHORT("java.lang.Short", "smallint", "(6)",  "Short"),
    LONG("java.lang.Long", "bigint", "(20)",  "Long"),
    FLOAT("java.lang.Float", "float", "",  "Float"),
    DOUBLE("java.lang.Double", "double", "",  "Double"),
    BOOLEAN("java.lang.Boolean", "tinyint", "(4)", "Boolean"),
    CHARACTER("java.lang.Character", "char", "(1)",  "Character"),

    // 其他封装类型
    STRING("java.lang.String", "varchar", "(255)",  "String"),
    DATE_SQL("java.sql.Date", "date", "",  "Date"),
    DATE_UTIL("java.util.Date", "date", "",  "Date"),
    TIME("java.sql.Time", "time", "",  "Time"),
    LOCAL_DATE_TIME("java.time.LocalDateTime", "datetime",  "", "LocalDateTime"),
    TIME_STAMP("java.sql.Timestamp", "timestamp",  "", "Timestamp"),

    // 补充类型
    BIG_DECIMAL("java.math.BigDecimal", "decimal",  "(11)", "BigDecimal"),
    BLOB("java.sql.Blob", "blob",  "", "Blob二进制"),
    CLOB("java.sql.Clob", "text",  "", "Clob长文本"),

    // mysql数据库本型
    DB_VARCHAR("varchar", "varchar", "(255)",  "varchar"),
    DB_TINY_INT("tinyint", "tinyint", "(4)",  "varchar"),
    DB_SMALL_INT("smallint", "smallint", "(6)",  "varchar"),
    DB_BIG_INT("bigint", "bigint", "(20)",  "varchar"),
    DB_CHAR("char", "char", "(1)",  "varchar"),
    DB_DATE("date", "date", "",  "varchar"),
    DB_TIME("time", "time", "",  "varchar"),
    DB_DATE_TIME("datetime", "datetime",  "",  "varchar"),
    DB_TIME_STAMP("timestamp", "timestamp",  "",   "varchar"),
    DB_DECIMAL("decimal", "decimal",  "(11)", "varchar"),
    DB_TEXT("text", "text",  "",  "varchar"),

    ;
    private String javaType;
    private String mysqlType;
    private String defaultLen;
    private String desc;

    MySqlTypeEnum(String javaType, String mysqlType, String defaultLen, String desc) {
        this.javaType = javaType;
        this.mysqlType = mysqlType;
        this.defaultLen = defaultLen;
        this.desc = desc;
    }

    public String getJavaType() {
        return javaType;
    }

    public void setJavaType(String javaType) {
        this.javaType = javaType;
    }

    public String getMysqlType() {
        return mysqlType;
    }

    public void setMysqlType(String mysqlType) {
        this.mysqlType = mysqlType;
    }

    public String getDefaultLen() {
        return defaultLen;
    }

    public void setDefaultLen(String defaultLen) {
        this.defaultLen = defaultLen;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static String getMysqlTypeByJavaType(String tyep , Boolean isDefault) {
        for (MySqlTypeEnum item : MySqlTypeEnum.values()) {
            if (item.getJavaType().equals(tyep)) {
                return isDefault ? item.getMysqlType() + item.getDefaultLen() : item.getMysqlType();
            }
        }
        return null;
    }
}
